<template>
<div>

  <el-form ref="form" :model="user" label-width="80px">
    <el-form-item label="名字">
      <el-input v-model="user.name"></el-input>
    </el-form-item>

    <el-form-item label="密码">
      <el-input  placeholder="请输入密码" v-model="user.password" show-password></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="user.sex">
        <el-radio label="男"></el-radio>
        <el-radio label="女"></el-radio>
      </el-radio-group>
    </el-form-item>

    <el-form-item label="出生日期">
        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="user.birthday" style="width: 100%;"></el-date-picker>
    </el-form-item>


    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import Qs from 'qs'
export default {
  name: "Update",
  data(){
    return{
      id:this.$route.params.id,
      user: {}
    }
  },
  mounted() {
    let vm = this;
    this.axios({
      url:`/localhost/vue/user/${vm.id}`,
      method:"get"
    }).then(function (res) {
      console.log(res.data.data)
      vm.user = res.data.data
    }).catch(function (err) {
      console.log(err)
    });
  },
  methods: {
    onSubmit() {
      let vm = this;

      this.axios({
        url:"/localhost/vue/user",
        method:"post",
        data: vm.user,
        transformRequest:[function (data) {

          return Qs.stringify(data);
        }],
      }).then(function (res) {
        console.log(res.data);
        if (res.data.code == 0){
          vm.$message.success("修改成功");
          vm.$router.push("/Home");
        }
      }).catch(function (err) {
        console.log(err);
      });
    }
  }
}
</script>

<style scoped>

</style>
